package base.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*事件处理类*/

public class TimerUtil {

	
	public static String zzw(Date d){
		
		int a = d.getHours();
		
		if(a>0 && a<=6){
			return "凌晨";
		}else if(a>6 && a<=10){
			return "上午";
		}else if(a>10 && a<=13){
			return "中午";
		}else if(a>13 && a<=18){
			return "下午";
		}else if(a>18 &a<=24){
			return "晚上";
		}
	
		//return d.getHours()+"";
		return "";
		
	}
	
	private static long getDayTime(int day) throws Exception{
		
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		Date beginDate = new Date();
		Calendar date = Calendar.getInstance();
		date.setTime(beginDate);
		date.set(Calendar.DATE, date.get(Calendar.DATE) - day);
		Date endDate = dft.parse(dft.format(date.getTime()));
		
		return endDate.getTime();
		
	}
	
	public static String getWeekOfDate(Date dt) {
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);

        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;

        return weekDays[w];
    }
	public static void main(String[] args) throws Exception {
		
		
		String str = "2017-09-21 21:55:44";
		String[] strArr = str.split(" ");
		String str1 = strArr[0]+" 00:00:00";
		
		SimpleDateFormat dft0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date0 = dft0.parse(str1); //今天
		
		Date today = dft0.parse(str); //输入时间
		
		
		
		//七天前的时间戳
		long day7 = getDayTime(6); //七天之内
		long day1 = getDayTime(1); //昨天
		long day = getDayTime(0); //当天
		
		dft0 = new SimpleDateFormat("HH:mm");
		if(today.getTime()>day){
			
			
			System.out.println("今天 "+zzw(today)+dft0.format(today));
		}else if(today.getTime()>day1){
			
			System.out.println("昨天"+zzw(today)+dft0.format(today));
		}else if(today.getTime()>day7){
			
			//"七天之内"
			System.out.println(getWeekOfDate(today)+dft0.format(today));
			//System.out.println(getWeekOfDate(today));
			
		}else{
			//"七天之外"
			dft0 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
			System.out.println(dft0.format(today));
		}
		
		
		//String s2 = dft0.format(day7);
		
		//System.err.println(s2);
		
		//System.out.println(today.getHours());
		
	}

	
}
